<?php

// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

$_MAMBOTS->registerFunction( 'onLog', 'NotifyDocumentOwner' );

function NotifyDocumentOwner( $params ) {
    global $mainframe, $my, $database, $mosConfig_mailfrom, $mosConfig_fromname, $mosConfig_sitename;


    $query = "SELECT o.user_id, u.email FROM #__docman_owners AS o INNER JOIN #__users as u ON o.user_id = u.id WHERE o.document_id = ".$params['document']->id;
    $database->setQuery($query);
    $rows = $database->loadObjectList();

    $query = "SELECT * FROM  #__users WHERE id = ".$my->id;
    $database->setQuery($query);
    $user = $database->loadObjectList();
    
    $userEmail = $user[0]->email;
    $userName  = $user[0]->name;
    $userNick  = $user[0]->username;
    $documentName = $params['document']->dmname;
    foreach((array)$rows as $key => $row){
        $ownerEmail = $row->email;
        include dirname(__FILE__).'/botnotifications/message.php';
        mosMail($mosConfig_mailfrom, $mosConfig_fromname, $ownerEmail, 'Download at '.$mosConfig_sitename, $message, false);
    }

}

?>